package com.power.using.mybomb.ui.fragment;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.power.using.mybomb.R;
import com.power.using.mybomb.base.ParentWithNaviFragment;
import com.power.using.mybomb.bean.User;
import com.power.using.mybomb.model.UserModel;
import com.power.using.mybomb.ui.LoginActivity;
import com.power.using.mybomb.ui.UserInfoActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.bmob.newim.BmobIM;
import cn.bmob.v3.BmobUser;

/**
 * Created by 聪明一只哈 on 2020/3/21.
 * Time: 2020/3/21  10:18
 */
public class SetFragment extends ParentWithNaviFragment {
    @BindView(R.id.v_top)
    View vTop;
    @BindView(R.id.tv_left)
    ImageView tvLeft;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_right)
    TextView tvRight;
    @BindView(R.id.tv_set_name)
    TextView tvSetName;
    @BindView(R.id.layout_info)
    RelativeLayout layoutInfo;
    @BindView(R.id.layout_blacklist)
    RelativeLayout layoutBlacklist;
    @BindView(R.id.iv_open_notification)
    ImageView ivOpenNotification;
    @BindView(R.id.iv_close_notification)
    ImageView ivCloseNotification;
    @BindView(R.id.rl_switch_notification)
    RelativeLayout rlSwitchNotification;
    @BindView(R.id.iv_open_voice)
    ImageView ivOpenVoice;
    @BindView(R.id.iv_close_voice)
    ImageView ivCloseVoice;
    @BindView(R.id.rl_switch_voice)
    RelativeLayout rlSwitchVoice;
    @BindView(R.id.view1)
    View view1;
    @BindView(R.id.iv_open_vibrate)
    ImageView ivOpenVibrate;
    @BindView(R.id.iv_close_vibrate)
    ImageView ivCloseVibrate;
    @BindView(R.id.rl_switch_vibrate)
    RelativeLayout rlSwitchVibrate;
    @BindView(R.id.view2)
    View view2;
    @BindView(R.id.btn_logout)
    Button btnLogout;

    @Override
    protected String title() {
        return "设置";
    }

    public static SetFragment newInstance() {
        SetFragment setFragment = new SetFragment();
        Bundle bundle = new Bundle();
        setFragment.setArguments(bundle);
        return setFragment;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        rootView = inflater.inflate(R.layout.fragment_set, container, false);
        initNaviView();
        ButterKnife.bind(this,rootView);
        String username = UserModel.getInstance().getCurrentUser().getUsername();
        tvSetName.setText(TextUtils.isEmpty(username)?"":username);
        return rootView;
    }

    @OnClick({R.id.layout_info, R.id.btn_logout})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.layout_info:

                Bundle bundle = new Bundle();
                bundle.putSerializable("u", BmobUser.getCurrentUser(User.class));
                startActivity(UserInfoActivity.class,bundle);
                break;
            case R.id.btn_logout:
                UserModel.getInstance().logOut();

                BmobIM.getInstance().disConnect();
                getActivity().finish();
                startActivity(LoginActivity.class,null);
                break;
        }
    }
}
